//
//  LoginVC.m
//  coffee
//
//  Created by student4 on 2020/12/6.
//  Copyright © 2020 MOSAD. All rights reserved.
//

#import "LoginVC.h"
#import "../../util/UserRequest.h"

@implementation LoginVC

-(void)viewDidLoad{
    [super viewDidLoad];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"注册" style:UIBarButtonItemStylePlain target:self action:@selector(regist)];
    _loginview = [[LoginView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    [_loginview viewInit];
    [[_loginview submit]addTarget:self action:@selector(submit) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_loginview];
}
-(void)regist{
    RegistVC *vc = [[RegistVC alloc]init];
    [self.navigationController pushViewController:vc animated:NO];
}
-(void)submit{
    NSLog(@"submit");
    UserReq *manager = [UserReq defaultUserRequest];
    LoginReq *request = [[LoginReq alloc]init];
//    [request setName:[[_loginview iname]text]];
    [request setName:@"esuala@tom.com"];
//    [request setPassword:[[_loginview ipwd]text]];
    [request setPassword:@"administer"];
    
    [manager login:request success:^{
        [self.navigationController popViewControllerAnimated:YES];
        [manager getInfo:@"self" success:^(UserInfo *info) {
            [self->_delegate setInfo:info];
        } failure:^(NSString *reason) {
            NSLog(@"%@",reason);
        }];
    } failure:^(NSString *reason) {
        NSLog(@"%@",reason);
    }];
}

@end




@implementation RegistVC

-(void)viewDidLoad{
    [super viewDidLoad];
    _registerview = [[RegistView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    [_registerview viewInit];
    [[_registerview submit]addTarget:self action:@selector(submit) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_registerview];
}
-(void)submit{
    UserReq *manager = [UserReq defaultUserRequest];
    // TODO 接入网络接口写注册
}

@end
